package com.xhh.greynewsapp.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.xhh.greynewsapp.R;
import com.xhh.greynewsapp.adapter.NewsViewPagerAdapter;
import com.xhh.greynewsapp.fragment.news.NewsTopFragment;
import com.xhh.greynewsapp.fragment.news.RecommendFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @description
 * @author: weiXhh
 * @create: 2020-05-26 14:02
 **/
public class NewsFragment extends Fragment {

    private static final String TAG = "NewsFragment";
    @BindView(R.id.news_tab)
    TabLayout tabLayout;

    @BindView(R.id.news_fragment_view_pager)
    ViewPager viewPager;

    private NewsViewPagerAdapter newsViewPagerAdapter;
    private List<Fragment> newsFragments = new ArrayList<>();


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_news, container, false);
        ButterKnife.bind(this, view);


        // 给tabLayout设置viewPager
        newsFragments.add(new RecommendFragment());
        newsFragments.add(new NewsTopFragment());
        newsViewPagerAdapter = new NewsViewPagerAdapter(getFragmentManager(), 0, newsFragments);
        viewPager.setAdapter(newsViewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    }

}
